package com.lesserpand.springcloudalibabacore.test.service.impl;

import com.lesserpand.springcloudalibabacore.config.rabbitmq.utils.ProviderUtils;
import com.lesserpand.springcloudalibabacore.test.dao.OrderItemDAO;
import com.lesserpand.springcloudalibabacore.test.entity.OrderDO;
import com.lesserpand.springcloudalibabacore.test.entity.OrderItemDO;
import com.lesserpand.springcloudalibabacore.test.entity.dto.OrderItemDTO;
import com.lesserpand.springcloudalibabacore.test.service.OrderItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bailuo
 * @version 2.0
 * @Description TODO
 * @Date Created in 2019/1/8 19:20
 */
@Service("orderItemService")
public class OrderItemServiceImpl implements OrderItemService {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderItemServiceImpl.class);

    @Autowired
    private ProviderUtils providerUtils;

    @Autowired
    private OrderItemDAO orderItemDAO;

    /**
     * 新增订单
     *
     * @param dto 订单信息
     */
    @Override
    public void save(OrderItemDTO dto) {
        OrderItemDO orderItemDO = new OrderItemDO();
        BeanUtils.copyProperties(dto, orderItemDO);
        try {
            orderItemDAO.save(orderItemDO);
        } catch (Exception e) {
            LOGGER.error("订单保存失败！", e);
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据订单id查询订单信息
     *
     * @param id 订单id
     */
    @Override
    public OrderDO findById(Long id) {
        OrderDO orderDO = null;
        try {
            orderDO = orderItemDAO.findById(id);
        } catch (Exception e) {
            LOGGER.error("查询失败！", e);
        }
        return orderDO;
    }
}
